package com.adbj.sychronizedtest;

public class BlockTest implements Runnable {



        static int count=0;

        @Override
        public synchronized void run() {
            increaseCount();
        }

        //静态方法是不属于当前实例的，而是属性类的 锁就是类的class对象锁
        private void increaseCount() {
            synchronized (this){
           // synchronized (BlockTest.class){
                for (int i = 0; i < 5; i++) {
                    System.out.println(Thread.currentThread().getName() + ":" + count++);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

        }

        public static void main(String[] args) {
            BlockTest syncTest1=new BlockTest();
            BlockTest syncTest2=new BlockTest();
            Thread thread1=new Thread(syncTest1,"thread1");
            Thread thread2=new Thread(syncTest2,"thread2");
            thread1.start();
            thread2.start();
        }

    }

